Skip to content

Fix G004: replace logging f-strings with lazy % formatting#191

Open
Copilot wants to merge 3 commits intomainfrom
copilot/g004-fix-linter-error
Open

Fix G004: replace logging f-strings with lazy % formatting#191
Copilot wants to merge 3 commits intomainfrom
copilot/g004-fix-linter-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

Ruff rule G004 flags f-strings in logging calls because string interpolation is eagerly evaluated even when the log level is disabled. This replaces all such f-strings with %s-style lazy formatting across the codebase and removes G004 from the suppression list in pyproject.toml.

Changes

  • 8 source files — convert logging.*(f"...")logging.*("...", ...) with %s placeholders
    • shell_utils.py, agent.py, prompt_parser.py, runner.py, session.py, mcp_utils.py, mcp_lifecycle.py, mcp_servers/codeql/client.py
  • pyproject.toml — remove "G004" from [tool.ruff.lint] ignore

Example

# Before
logging.debug(f"Connecting mcp server: {entry.name}")
logging.warning(f"Task {task_name!r} attempt {attempt + 1} failed: {exc}")

# After
logging.debug("Connecting mcp server: %s", entry.name)
logging.warning("Task %r attempt %s failed: %s", task_name, attempt + 1, exc)

Copilot AI linked an issue Apr 2, 2026 that may be closed by this pull request
…om suppression list

Agent-Logs-Url: https://github.com/GitHubSecurityLab/seclab-taskflow-agent/sessions/fc7d4cac-0cf0-4a55-b9a1-b00a172e1c03

Co-authored-by: kevinbackhouse <4358136+kevinbackhouse@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix linter error G004 and remove suppression from pyproject.toml Fix G004: replace logging f-strings with lazy % formatting Apr 2, 2026
Copilot AI requested a review from kevinbackhouse April 2, 2026 15:15
@kevinbackhouse kevinbackhouse marked this pull request as ready for review April 2, 2026 15:24
Copilot AI review requested due to automatic review settings April 2, 2026 15:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the codebase to comply with Ruff rule G004 by replacing eager f-string interpolation inside logging calls with lazy %-style formatting, and then tightening linting by removing G004 from the Ruff ignore list.

Changes:

  • Replaced logging.*(f"...") calls with logging.*("...%s...", ...) across affected modules.
  • Updated log message formatting to use %s / %r placeholders where appropriate.
  • Removed G004 from pyproject.toml’s Ruff ignore list to enforce the rule going forward.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/seclab_taskflow_agent/shell_utils.py Uses lazy logging formatting for shell execution logs.
src/seclab_taskflow_agent/session.py Converts session checkpoint and corrupt-file warnings to lazy formatting.
src/seclab_taskflow_agent/runner.py Replaces multiple logging f-strings (critical/debug/error/exception/warning) with lazy formatting.
src/seclab_taskflow_agent/prompt_parser.py Uses lazy formatting for parse errors and invalid global variable messages.
src/seclab_taskflow_agent/mcp_utils.py Converts debug logs (including multiline debug output) to lazy formatting.
src/seclab_taskflow_agent/mcp_servers/codeql/client.py Converts source prefix parsing error log to lazy formatting.
src/seclab_taskflow_agent/mcp_lifecycle.py Uses lazy formatting for MCP lifecycle connect/cleanup and stream output logs.
src/seclab_taskflow_agent/agent.py Updates hook lifecycle logging to lazy formatting and removes an extra trailing space.
pyproject.toml Removes G004 from Ruff ignore list to enforce logging best practices.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

G004

3 participants